home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-01 | 11.0 KB | 281 lines | [TEXT/SPM ] |
- /*
- IC Text Whats.c
-
- */
-
- #include <Scrap.h>
-
- #include "IC Globals.h"
-
- #include "IC Window Globals.h"
- #include "IC Types.h"
- #include "IC API.h"
- #include "IC Globals.h"
- #include "IC Misc Subs.h"
- #include "IC Subs.h"
- #include "IC Text.h"
- #include "IC Dialogs.h"
- #include "IC Document.h"
- #include "IC Text Whats.h"
-
- pascal void DrawTextProc(DialogPtr window,short item){
- Rect r;
- short savefont,savemode,savesize;
- Style saveface;
-
- savefont=window->txFont;
- saveface=window->txFace;
- savemode=window->txMode;
- savesize=window->txSize;
-
- TextDraw(WindowInfo[GetWindowType(window)].items[item]->data);
-
- GetDItemRect(window,item,&r);
- InsetRect(&r,-3,-3);
- PenNormal();
- FrameRect(&r);
-
- TextFont(savefont);
- TextFace(saveface);
- TextMode(savemode);
- TextSize(savesize);
- }
-
- Boolean HaveTextSelection(WindowType wt){
- long start_sel,end_sel;
- Boolean ret=false;
-
- if (GetSelectedItem(wt)>0){
- TextGetSelect(WindowInfo[wt].items[GetSelectedItem(wt)]->data,&start_sel,&end_sel);
- ret=(start_sel!=end_sel);
- }
-
- return ret;
- }
-
- void AdjustTextMenu(WindowType wt){
- Boolean enable_cut=false,enable_paste=false,enable_select_all=false;
- Boolean enable_undo=false;
- long offset;
- MenuHandle mh;
- Handle texth;
- long text_size;
- short search_text;
- long cr_pos;
- short item;
- OSErr err;
- long sel_start,sel_end;
-
- item=GetSelectedItem(wt);
- if ((wt!=WT_None)&&(item>0)){
- enable_cut=HaveTextSelection(wt);
- offset=0;
- enable_paste=(GetScrap((Handle)0,'TEXT',&offset)>0);
- TextGetSelect(WindowInfo[wt].items[item]->data,&sel_start,&sel_end);
- TextGetSize(WindowInfo[wt].items[item]->data,&text_size);
- enable_select_all=((sel_start!=0)||(sel_end!=text_size));
- }
-
- // deal with the nasty paste problem, ie preventing them pasting CRs into single line fields
- if ((enable_paste)&&(WindowInfo[wt].items[item]->flags&(1<<tf_single_line))){
- texth=NewHandle(0);
- err=MemError();
- if (err==noErr){
- offset=0;
- text_size=GetScrap(texth,'TEXT',&offset);
- if (text_size>0){
- search_text=0x0d0d;
- cr_pos=Munger(texth,0,(Ptr)&search_text,1, }
- }
-
- OSErr WhatOpenText(WindowType wt,short item){
- OSErr err;
- Str31 key;
- long attr;
- Handle texth;
- long junk,flags;
- Boolean pstring,scrambled;
- short font,size;
- Rect r;
-
- WindowInfo[wt].items[item]->data=(Ptr)0;
- WindowInfo[wt].items[item]->spare_data=(Ptr)0;
- texth=(Handle)0;
-
- SetPString(key,1,WindowInfo[wt].items[item]->key);
- flags=WindowInfo[wt].items[item]->flags;
- pstring=flags&(1<<tf_pstring);
- scrambled=flags&(1<<tf_scrambled);
-
- if (flags&(1<<tf_monospace)){
- font=monaco;
- size=9;
- } else {
- font=systemFont;
- size=12;
- }
-
- err=ICMapErr(ICGetPrefHandle(GetInstance(),key,&attr,&texth));
- if (err==noErr){
- ProcessAttributes(wt,item,attr);
- if (pstring)
- Munger(texth,0,(Ptr)0,1,(Ptr)&junk,0);// strip the first char
- if (scrambled)
- ScrambleHandle(texth);
- err=TextCreate(&(WindowInfo[wt].items[item]->data),WindowInfo[wt].window,item,font,
- size,IsLocked(wt,item));
- }
- if (err==noErr){
- SetDItemHandle(WindowInfo[wt].window,item,(Handle)gDrawTextProc);
- junk=GetHandleSize(texth);
- // (*texth)[junk]=0;
- TextInsert(WindowInfo[wt].items[item]->data,texth);
- }
-
- // build password dialog string
- if ((err==noErr)&&(scrambled)){
- WindowInfo[wt].items[item]->spare_data=WindowInfo[wt].items[item]->data;
- WindowInfo[wt].items[item]->data=(Ptr)0;
- GetDItemRect(WindowInfo[wt].window,item,&r);
- OffsetRect(&r,16000,0);
- TextMove(WindowInfo[wt].items[item]->spare_data,&r);
- BlockFill(*texth,GetHandleSize(texth),'•');
-
- err=TextCreate(&(WindowInfo[wt].items[item]->data),WindowInfo[wt].window,item,font,
- size,IsLocked(wt,item));
-
- if (err==noErr)
- TextInsert(WindowInfo[wt].items[item]->data,texth);
- }
-
- if (texth!=(Handle)0)
- DisposeHandle(texth);
-
- return err;
- }
-
- OSErr WhatFlushText(WindowType wt,short item){
- OSErr err;
- Str31 key;
- Handle texth=(Handle)0,oldtexth=(Handle)0;
- long attr,flags,texts,oldtexts;
- short i;
- Boolean pstring,scrambled;
-
- texth=oldtexth=(Handle)0;
- SetPString(key,1,WindowInfo[wt].items[item]->key);
- flags=WindowInfo[wt].items[item]->flags;
- pstring=flags&(1<<tf_pstring);
- scrambled=flags&(1<<tf_scrambled);
- err=ICMapErr(ICGetPrefHandle(GetInstance(),key,&attr,&oldtexth));
- if (err==noErr){
- if ((pstring)&&(GetHandleSize(oldtexth)==0)){
- // pref is non-existent or empty, turn oldtext into a handle for an empty pascal string
- SetHandleSize(oldtexth,1);
- err=MemError();
- if (err==noErr)
- **oldtexth=0; // terminate the empty pstring
- }
- }
- if (err==noErr){
- texth=NewHandle(0);
- err=MemError();
- }
-
- if (err==noErr){
- if (scrambled){
- TextGet(WindowInfo[wt].items[item]->spare_data,texth);
- ScrambleHandle(texth);
- } else
- TextGet(WindowInfo[wt].items[item]->data,texth);
- if (pstring){
- if (GetHandleSize(texth)>255)
- SetHandleSize(texth,255);
- i=GetHandleSize(texth)*0x0101; // puts it into both bytes!
- // insert the size byte into the handle at position zero
- Munger(texth,0L,(Ptr)0,0L,&i,1);// if this errors, we lose data
- }
- // should it go out to the prefs file?
- texts=GetHandleSize(texth);
- oldtexts=GetHandleSize(oldtexth);
- {
- Boolean islocked=IsLocked(wt,item);
- Boolean sameSize=(texts==oldtexts);
- Boolean sameText=true;
-
- if (sameSize) // only check the text if the sizes are the same
- sameText=BlockCompare(*texth,*oldtexth,texts);
-
- if (islocked){
- // can't update the doc, it is a locked field
- } else if (sameSize&&sameText){
- // nothing changed, so don't update the doc
- } else {
- // either the size or text is different, update the doc
-
- err=ICMapErr(ICSetPrefHandle(GetInstance(),key,ICattr_no_change,texth));
-
- if (err==noErr)
- DirtyDocument();
- }
- }
- }
- if (texth!=(Handle)0)
- DisposeHandle(texth);
- if (oldtexth!=(Handle)0)
- DisposeHandle(oldtexth);
-
- return err;
- }
-
- OSErr WhatCloseText(WindowType wt,short item){
- long flags;
- Boolean scrambled;
-
- flags=WindowInfo[wt].items[item]->flags;
- scrambled=flags&(1<<tf_scrambled);
- TextDestroy(&(WindowInfo[wt].items[item]->data));
- if (scrambled)
- TextDestroy(&(WindowInfo[wt].items[item]->spare_data));
- return noErr;
- }
-
- OSErr WhatClickText(WindowType wt,short item,EventRecord* er){
- JustSelectTextItem(wt,item);
- TextClick(WindowInfo[wt].items[item]->data,er);
- return noErr;
- }
-
- OSErr WhatKeyText(WindowType wt,short item,EventRecord* er){
- long flags;
- Boolean scrambled,single_line;
- char ch;
- long sel_start,sel_end;
-
- flags=WindowInfo[wt].items[item]->flags;
- scrambled=flags&(1<<tf_scrambled);
- single_line=flags&(1<<tf_single_line);
- ch=(er->message&charCodeMask)&0xff;
-
- // if a return on a single line or whitespace with scrambled
- if (((single_line)&&(ch==13))||((scrambled)&&(ch!=8)&&(ch<' ')))
- SysBeep(1);
- else {
- if ((IsLocked(wt,item))&&(DirtyKey(ch)))
- LockedAlert(wt,item);
- else {
- if (scrambled){
- TextGetSelect(WindowInfo[wt].items[item]->data,&sel_start,&sel_end);
- TextSetSelect(WindowInfo[wt].items[item]->spare_data,sel_start,sel_end);
- TextKey(WindowInfo[wt].items[item]->spare_data,er);
- if ((ch!=8)&&(DirtyKey(ch)))
- er->message='•';
- }
-
- TextKey(WindowInfo[wt].items[item]->data,er);
- }
- }
-
- return noErr;
- }
-